package cn.yunhe.servlet;

import cn.yunhe.entity.OrderDetail;
import cn.yunhe.entity.Product;
import cn.yunhe.entity.User;
import cn.yunhe.service.OrderDetailService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;


@WebServlet("/AddOrderDetailServlet")
public class AddOrderDetailServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = req.getSession();
        Object userstr = session.getAttribute("Curr_User");

        if(userstr!=null){
            User user= (User) userstr;
            int epid = Integer.parseInt(req.getParameter("epid"));
            Product product = new Product(epid);
            OrderDetail orderDetail = new OrderDetail(1, user.getUserid(), product);
            OrderDetailService orderDetailService = new OrderDetailService();
            boolean flag = orderDetailService.searchProductOrderOfUser(orderDetail);
            if (flag) {
                boolean sign = orderDetailService.addShopping(orderDetail);
            }
        }else{

        }
    }
}
